package com.ruoyi.production.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.production.mapper.PesticideReturnMapper;
import com.ruoyi.production.domain.PesticideReturn;
import com.ruoyi.production.service.IPesticideReturnService;

/**
 * 农药退回Service业务层处理
 *
 * @author ruoyi
 * @date 2021-07-17
 */
@Service
public class PesticideReturnServiceImpl implements IPesticideReturnService
{
    @Autowired
    private PesticideReturnMapper pesticideReturnMapper;

    /**
     * 查询农药退回
     *
     * @param pesticideReturnId 农药退回ID
     * @return 农药退回
     */
    @Override
    public PesticideReturn selectPesticideReturnById(Long pesticideReturnId)
    {
        return pesticideReturnMapper.selectPesticideReturnById(pesticideReturnId);
    }

    /**
     * 查询农药退回列表
     *
     * @param pesticideReturn 农药退回
     * @return 农药退回
     */
    @Override
    public List<PesticideReturn> selectPesticideReturnList(PesticideReturn pesticideReturn)
    {
        return pesticideReturnMapper.selectPesticideReturnList(pesticideReturn);
    }

    /**
     * 新增农药退回
     *
     * @param pesticideReturn 农药退回
     * @return 结果
     */
    @Override
    public int insertPesticideReturn(PesticideReturn pesticideReturn)
    {
        pesticideReturn.setCreateTime(DateUtils.getNowDate());
//        pesticideReturnMapper.updatePesticideAmount(pesticideReturn);
        return pesticideReturnMapper.insertPesticideReturn(pesticideReturn);
    }

    /**
     * 修改农药退回
     *
     * @param pesticideReturn 农药退回
     * @return 结果
     */
    @Override
    public int updatePesticideReturn(PesticideReturn pesticideReturn)
    {
        pesticideReturn.setUpdateTime(DateUtils.getNowDate());
        if(pesticideReturn.getApproval()==1) {
            pesticideReturnMapper.updatePesticideAmount(pesticideReturn);
            return pesticideReturnMapper.updatePesticideReturn(pesticideReturn);
        }
        else
            return pesticideReturnMapper.updatePesticideReturn(pesticideReturn);
    }

    /**
     * 批量删除农药退回
     *
     * @param pesticideReturnIds 需要删除的农药退回ID
     * @return 结果
     */
    @Override
    public int deletePesticideReturnByIds(Long[] pesticideReturnIds)
    {
        return pesticideReturnMapper.deletePesticideReturnByIds(pesticideReturnIds);
    }

    /**
     * 删除农药退回信息
     *
     * @param pesticideReturnId 农药退回ID
     * @return 结果
     */
    @Override
    public int deletePesticideReturnById(Long pesticideReturnId)
    {
        return pesticideReturnMapper.deletePesticideReturnById(pesticideReturnId);
    }

    /**
     * 获取农药类型下拉框
     *
     * @param
     * @return 结果
     */
    @Override
    public List<PesticideReturn> getPesticideType(){
        return pesticideReturnMapper.getPesticideType();
    }

    /**
     * 获取农药名称下拉框
     *
     * @param
     * @return 结果
     */
    @Override
    public List<PesticideReturn> getPesticideName(){
        return pesticideReturnMapper.getPesticideName();
    }

    /**
     * 获取用户下拉框
     *
     * @param
     * @return 结果
     */
    @Override
    public List<PesticideReturn> getUserName(){
        return pesticideReturnMapper.getUserName();
    }

    /**
     * 获取有效含量下拉框
     *
     * @param pesticideNameId 农药名称ID
     * @return 结果
     */
    @Override
    public List<String> getContent(Long pesticideNameId){
        return pesticideReturnMapper.getContent(pesticideNameId);
    }

    /**
     * 获取购自公司下拉框
     *
     * @param pesticideNameId 农药名称ID
     * @return 结果
     */
    @Override
    public List<String> getOriginCompany(Long pesticideNameId){
        return pesticideReturnMapper.getOriginCompany(pesticideNameId);
    }
}
